#include "workflowdialog.h"
#include "ui_workflowdialog.h"
#include"sourcemanage.h"
#include "conditioneditdialog.h"
#include"delegate.h"

WorkFlowDialog::WorkFlowDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::WorkFlowDialog)
{
    ui->setupUi(this);
    ComboxDelegate *pComboxDelegate=new ComboxDelegate(this,7);
    ui->tableWidget->setItemDelegateForColumn(3,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(10,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(15,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(16,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(22,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(23,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(24,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(28,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(29,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(30,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(31,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(32,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(33,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(34,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(35,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(36,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(37,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,8);
    ui->tableWidget->setItemDelegateForColumn(38,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,9);
    ui->tableWidget->setItemDelegateForColumn(19,pComboxDelegate);
    pComboxDelegate=new ComboxDelegate(this,10);
    ui->tableWidget->setItemDelegateForColumn(9,pComboxDelegate);

    list1=SM->options.value("OnOffType");
    list2=SM->options.value("DirectType");
    workFlow=SM->GetWorkFlow();
    LoadData();

//    QList<WorkStep> workSteps;
//    flows.insert("name1",workSteps);
//    WorkStep step;
//    workSteps.append(step);
//    flows.insert("name2",workSteps);
//    flows.insert("name3",workSteps);
}

WorkFlowDialog::~WorkFlowDialog()
{
    //qDebug()<<"WorkFlowDialog::~WorkFlowDialog()";
    delete ui;
}

void WorkFlowDialog::LoadData()
{
    disconnect(ui->listWidget,SIGNAL(currentRowChanged(int)),this,SLOT(on_listWidget_currentRowChanged(int)));
    QList<QString> names=workFlow.GetFlowNames();
    ui->listWidget->clear();
    ui->listWidget->addItems(names);
    ui->listWidget->setCurrentRow(0);
    connect(ui->listWidget,SIGNAL(currentRowChanged(int)),this,SLOT(on_listWidget_currentRowChanged(int)));

    QModelIndex index=ui->listWidget->currentIndex();
    if(index.isValid()==false) return;
    on_listWidget_currentRowChanged(0);
}

void WorkFlowDialog::on_pushButton_AddFlow_clicked()
{
    QString name=ui->lineEdit_Name->text();//"Default"
    if(workFlow.IsExistFlow(name))
    {
        QMessageBox::information(this,tr("提示"),tr("该工作流程名已经存在！"));
        return;
    }

    disconnect(ui->listWidget,SIGNAL(currentRowChanged(int)),this,SLOT(on_listWidget_currentRowChanged(int)));
    ui->listWidget->addItem(name);
    connect(ui->listWidget,SIGNAL(currentRowChanged(int)),this,SLOT(on_listWidget_currentRowChanged(int)));
    QList<WorkStep> steps;
    workFlow.InsetFlow(name,steps);
}

void WorkFlowDialog::on_pushButton_DeleteFlow_clicked()
{
    QModelIndex index=ui->listWidget->currentIndex();
    if(index.isValid()==false) return;
    QString name=ui->listWidget->currentItem()->text();
    if(name=="打开真空"||name=="关闭真空"||name=="打开等离子体"||name=="关闭等离子体")
    {
       QMessageBox::information(this,tr("提示"),tr("系统流程无法删除！"));
       return;
    }

    disconnect(ui->listWidget,SIGNAL(currentRowChanged(int)),this,SLOT(on_listWidget_currentRowChanged(int)));
    QListWidgetItem *pItem=ui->listWidget->takeItem(index.row());
    connect(ui->listWidget,SIGNAL(currentRowChanged(int)),this,SLOT(on_listWidget_currentRowChanged(int)));
    delete pItem;
    workFlow.RemoveFlow(name);
}

void WorkFlowDialog::on_pushButton_AddState_clicked()
{
    QModelIndex index=ui->listWidget->currentIndex();
    if(index.isValid()==false) return;

    QString name=ui->listWidget->currentItem()->text();
    if(workFlow.GetWorkSteps(name).count()>=16)
    {
        QMessageBox::information(this,tr("提示"),tr("一个工作流程状态数不能超过16个"));
        return;
    }

    WorkStep step;
    workFlow.AddStep(name,step);

    on_listWidget_currentRowChanged(index.row());
}

void WorkFlowDialog::on_pushButton_InsetState_clicked()
{
    QModelIndex index=ui->listWidget->currentIndex();
    if(index.isValid()==false) return;
    QModelIndex index1=ui->tableWidget->currentIndex();
    if(index1.isValid()==false) return;

    QString name=ui->listWidget->currentItem()->text();
    if(workFlow.GetWorkSteps(name).count()>=16)
    {
        QMessageBox::information(this,tr("提示"),tr("一个工作流程状态数不能超过16个"));
        return;
    }

    WorkStep step;
    workFlow.InsetStep(name,index1.row(),step);

    on_listWidget_currentRowChanged(index.row());
}

void WorkFlowDialog::on_pushButton_DeleteState_clicked()
{
    QModelIndex index=ui->listWidget->currentIndex();
    if(index.isValid()==false) return;
    QModelIndex index1=ui->tableWidget->currentIndex();
    if(index1.isValid()==false) return;

    QString name=ui->listWidget->currentItem()->text();
    workFlow.RemoveStep(name,index1.row());

    on_listWidget_currentRowChanged(index.row());
}

//
void WorkFlowDialog::on_tableWidget_itemChanged(QTableWidgetItem *item)
{  
    QModelIndex index=ui->listWidget->currentIndex();
    if(index.isValid()==false) return;

    QString name=ui->listWidget->item(index.row())->text();
    QList<WorkStep> workSteps=workFlow.GetWorkSteps(name);
    int count=workSteps.count();
    //ui->tableWidget->setRowCount(count);
    //int count=ui->tableWidget->rowCount();
    qDebug()<<"count"<<count;
    for(int row=0;row<count;row++)
    {
        int column=0;
        workSteps[row].id=ui->tableWidget->item(row,column++)->text().toInt();
        workSteps[row].name=ui->tableWidget->item(row,column++)->text();
        //workSteps[row].name=ui->tableWidget->item(row,column++)->text();//WorkStepCondition
        column++;
        workSteps[row].instrumentState=ui->tableWidget->item(row,column++)->text();
        workSteps[row].runningInfor=ui->tableWidget->item(row,column++)->text();
        workSteps[row].runningDelay=ui->tableWidget->item(row,column++)->text().toInt();
        workSteps[row].finishedInfor=ui->tableWidget->item(row,column++)->text();
        workSteps[row].finishedDelay=ui->tableWidget->item(row,column++)->text().toInt();
        workSteps[row].timeOut=ui->tableWidget->item(row,column++)->text().toInt();
        workSteps[row].exceptFlowName=ui->tableWidget->item(row,column++)->text();
        workSteps[row].plasmaOnOff=ui->tableWidget->item(row,column++)->text();//
        workSteps[row].cooler=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].auxiliary=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].atomization=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].added=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].switchValue.coolWarter=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].switchValue.coolGas=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].coolwarter=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].atomizationT=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].switchValue.peristalticPumpD=list2.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].peristalticPumpSpeed=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].powerRf=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].voltageRfOnOff=ui->tableWidget->item(row,column++)->text();//
        workSteps[row].restoreRfOnOff=ui->tableWidget->item(row,column++)->text();//
        workSteps[row].switchValue.onRf=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].motorZ=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].motorX=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].motorY=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].groundOnOff=ui->tableWidget->item(row,column++)->text();//
        workSteps[row].readyLedOnOff=ui->tableWidget->item(row,column++)->text();//
        workSteps[row].switchValue.mechanicPump1=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].switchValue.turboPump=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].switchValue.vacuumGauge=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].switchValue.frontValve=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].switchValue.angleValve=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].switchValue.ventValve=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].switchValue.turboVent=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].switchValue.collisionGas1=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].collisionGasHe=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].switchValue.collisionGas2=list1.indexOf(ui->tableWidget->item(row,column++)->text());
        workSteps[row].collisionGasH2=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].samplingConeT=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].lenGroupOnOff=ui->tableWidget->item(row,column++)->text();//
        workSteps[row].extractionLen=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].hexapole=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].len1=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].len2=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].len3=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].focusingLen=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].deflectionLen1=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].deflectionLen2=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].deflectionLen3=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].deflectionLen4=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].quadrupole=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].analogDetector=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].digitalDetector=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].standardResolution=ui->tableWidget->item(row,column++)->text().toDouble();
        workSteps[row].highResolution=ui->tableWidget->item(row,column++)->text().toDouble();
    }
    qDebug()<<"count"<<count;
    workFlow.InsetFlow(name,workSteps);
}

void WorkFlowDialog::on_listWidget_currentRowChanged(int currentRow)//
{
    disconnect(ui->tableWidget,SIGNAL(itemChanged(QTableWidgetItem*)),
               this,SLOT(on_tableWidget_itemChanged(QTableWidgetItem*)));

    QString name=ui->listWidget->item(currentRow)->text();
    QList<WorkStep> workSteps=workFlow.GetWorkSteps(name);
    int count=workSteps.count();
    ui->tableWidget->setRowCount(count);
    for(int row=0;row<count;row++)
    {
        int column=0;
        QTableWidgetItem *pItem;
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).id));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(workSteps.at(row).name);
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText((workSteps[row].IsCondition()==true)?"......":"");
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(workSteps.at(row).instrumentState);
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(workSteps.at(row).runningInfor);
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).runningDelay));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(workSteps.at(row).finishedInfor);
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).finishedDelay));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).timeOut));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(workSteps.at(row).exceptFlowName);
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(workSteps.at(row).plasmaOnOff);//
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).cooler));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).auxiliary));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).atomization));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).added));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.coolWarter));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.coolGas));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).coolwarter));//
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).atomizationT));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list2.at(workSteps.at(row).switchValue.peristalticPumpD));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).peristalticPumpSpeed));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).powerRf));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(workSteps.at(row).voltageRfOnOff);//emit
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(workSteps.at(row).restoreRfOnOff);//emit
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.onRf));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).motorZ));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).motorX));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).motorY));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(workSteps.at(row).groundOnOff);//
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(workSteps.at(row).readyLedOnOff);//
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.mechanicPump1));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.turboPump));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.vacuumGauge));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.frontValve));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.angleValve));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.ventValve));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.turboVent));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.collisionGas1));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).collisionGasHe));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(list1.at(workSteps.at(row).switchValue.collisionGas2));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).collisionGasH2));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).samplingConeT));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(workSteps.at(row).lenGroupOnOff);
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).extractionLen));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).hexapole));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).len1));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).len2));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).len3));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).focusingLen));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).deflectionLen1));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).deflectionLen2));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).deflectionLen3));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).deflectionLen4));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).quadrupole));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).analogDetector));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).digitalDetector));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).standardResolution));
        ui->tableWidget->setItem(row,column++,pItem);
        pItem=new QTableWidgetItem;
        pItem->setText(QString::number(workSteps.at(row).highResolution));
        ui->tableWidget->setItem(row,column++,pItem);
    }
    connect(ui->tableWidget,SIGNAL(itemChanged(QTableWidgetItem*)),
               this,SLOT(on_tableWidget_itemChanged(QTableWidgetItem*)));
}

void WorkFlowDialog::on_pushButton_Ok_clicked()
{
    SM->SetWorkFlow(workFlow);
    int state=FM->SaveToFile(FM->GetWorkFlowFile(),&workFlow);

    this->close();
}

void WorkFlowDialog::on_pushButton_Cancle_clicked()
{
    QMessageBox::StandardButton button=QMessageBox::question(this,tr("询问"),tr("退出将丢失修改的内容，确认退出？"));
    if(button==QMessageBox::Yes)
    {
        this->close();
    }
    else if(button==QMessageBox::No)
    {

    }
    else if(button==QMessageBox::Cancel||QMessageBox::Close)
    {

    }
}

void WorkFlowDialog::on_tableWidget_pressed(const QModelIndex &index)
{
    if(index.column()!=2) return;
    int currentRow=index.row();
    QString name=ui->listWidget->currentItem()->text();
    QList<WorkStep> workSteps=workFlow.GetWorkSteps(name);
    QList<WorkStepCondition> conditions=workSteps.at(currentRow).conditions
;
    ConditionEditDialog conditionEditDialog;
    conditionEditDialog.LoadData(conditions);
    int state=conditionEditDialog.exec();
    //qDebug()<<"state"<<state;
    if(state==1)
    {
        workSteps[currentRow].conditions=conditionEditDialog.GetData();
        workFlow.InsetFlow(name,workSteps);

        QTableWidgetItem *pItem=new QTableWidgetItem;
        pItem->setText((workSteps[currentRow].IsCondition()==true)?"......":"");
        ui->tableWidget->setItem(currentRow,index.column(),pItem);
    }
}
